package timelimit

import (
	"fmt"
	"time"
)

func timeLimit() (int, error) {
	var result int
	var err error
	done := make(chan struct{})
	go func() {
		result, err = doSomeWork()
		close(done)
	}()

	select {
	case <-done:
		return result, err
	case <-time.After(2 * time.Second): //两秒后返回
		return 0, fmt.Errorf("Work TimeOut")
	}

}

func doSomeWork() (int, error) {
	return 1, nil
}
